package com.oocl.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.exception.MyException;
import com.oocl.pojo.Food;
import com.oocl.service.impl.FoodServiceImpl;

/**
 * Servlet implementation class UpdateServlet
 */
public class UpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String fid=request.getParameter("fid");
		String fname=request.getParameter("fname");
		String ftype=request.getParameter("ftype");
		String fimage=request.getParameter("fimage");
		double price=Double.parseDouble(request.getParameter("price"));
		String mid=(String)request.getSession().getAttribute("mid");
		
		Food f=new Food();
		f.setFid(fid);
		f.setFimage(fimage);
		f.setFname(fname);
		f.setFtype(ftype);
		f.setIcnum(mid);
		f.setPrice(price);
		
		FoodServiceImpl fsi=new FoodServiceImpl();
		try {
			fsi.update(f);
			request.getRequestDispatcher("").forward(request, response);  //更新完跳转页面
		} catch (MyException e) {
			request.getRequestDispatcher("exception.jsp").forward(request, response);
		}
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
